<?php
if ( !defined( "IN_OP" ) )
{
    exit( "You can't access this file directly..." );
}
$ui = new ui();
$tpl = new Template2();
$fieldArr = array( "method" => "5", "gametype" => "0", "round" => "0", "lotto_id" => "0", "betcontent" => "", "orate" => "", "nrate" => "", "pagename" => "2", "paperopen" => date( "Y-m-d" ) );
$tpl->load( "main", "rate27.htm" );
$disk = "a";
if ( isset( $_GET['disk'] ) )
{
    $disk = $_GET['disk'];
}
else if ( isset( $_POST['disk'] ) )
{
    $disk = $_POST['disk'];
}
$fpLink = "srate27";
$rateTable = "rate27";
include( "admin_menu.php" );
include( "rate_menu.php" );
srateMenu( "srate27", $disk );
$tpl->set( "action", "op.php?op=admin&fp={$fpLink}&disk=".$disk );
if ( $disk == "a" )
{
    $setRateFlag = true;
}
else
{
    $setRateFlag = false;
}
$idisk = strpos( "0abcd", $disk );
$subid = 0;
$id = 0;
$rs = getdb( "!!select * from {$rateTable} where lotto_id={$id} and disk={$idisk} order by subid" );
if ( $rs->eof )
{
    $sql = "insert into {$rateTable} (lotto_id,disk,subid,r01,r02,r03,r04,r05,r06,r07,r08,r09,r10,r11,r12) values "."({$id},{$idisk},2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2, 4.2),"."({$id},{$idisk},3,10.5,10.5,10.5,10.5,10.5,10.5,10.5,10.5,10.5,10.5,10.5,10.5),"."({$id},{$idisk},4,33.0,33.0,33.0,33.0,33.0,33.0,33.0,33.0,33.0,33.0,33.0,33.0),"."({$id},{$idisk},5, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108)";
    getdb( $sql );
    $rs = getdb( "!!select * from {$rateTable} where lotto_id={$id} and disk={$idisk} order by subid" );
}
if ( ispost( ) )
{
    while ( !$rs->eof )
    {
        $subid = $rs->f['subid'];
        $fields = array();
        $i = 1;
        while ( $i <= 12 )
        {
            $htmField = "r27_{$subid}_".d2( $i );
            $tabField = "r".d2( $i );
            $temp = floatval( $_POST[$htmField] );
            if ( $temp != $rs->f[$tabField] )
            {
                $fields[$htmField] = $temp;
            }
            ++$i;
        }
        if ( count( $fields ) == 0 )
        {
            $rs->next();
            continue;
        }
        $sql = "update {$rateTable} set ";
        foreach ( $fields as $key => $temp )
        {
            $tabField = "r".d2( substr( $key, 6, 2 ) );
            $sql .= " {$tabField} = {$temp}, ";
            if ( $setRateFlag )
            {
                $fieldArr['betcontent'] = GetBetContentForSetRateRecord( $key );
                $fieldArr['orate'] = $rs->f[$tabField];
                $fieldArr['nrate'] = $temp;
                setRateRecord( $fieldArr );
            }
        }
        if ( substr( $sql, 0 - 2 ) == ", " )
        {
            $sql = substr( $sql, 0, strlen( $sql ) - 2 );
        }
        $sql .= " WHERE lotto_id={$id} and disk={$idisk} and subid={$subid}";
        getdb( $sql );
        $rs->next();
    }
    $rs = getdb( "!!select * from {$rateTable} where lotto_id={$id} and disk={$idisk} order by subid" );
}
$htm = "";
while ( !$rs->eof )
{
    $subid = $rs->f['subid'];
    $htm .= "<table border='0' cellspacing='0' cellpadding='3'><tr><tr><td colspan='2' bgcolor='#5A79C6' align='center'>"."<font color='#FFFFFF'>{$rs->f['subid']}肖</font></td></tr><td valign='top'>"."<table cellSpacing='1' cellPadding='3' border='0'><tr>";
    $i = 1;
    while ( $i <= 6 )
    {
        $ii = d2( $i );
        $val = trimfloat( $rs->f["r".d2( $i )], 1 );
        $htm .= "<td bgColor='#c0d6eb'><div align='center'>{$g_chinayear[$i]}</td></div><td bgColor='#e7ebef'>"."<input size='5' name=\"r27_{$subid}_{$ii}\" value='{$val}'>"."<input type='button' value='-' onclick=\"m1(r27_{$subid}_{$ii},-0.01)\">"."<input type='button' value='+' onclick=m1(r27_{$subid}_{$ii},0.01)></td>";
        ++$i;
    }
    $htm .= "</tr><tr>";
    $i = 7;
    while ( $i <= 12 )
    {
        $ii = d2( $i );
        $val = trimfloat( $rs->f["r".d2( $i )], 1 );
        $htm .= "<td bgColor='#c0d6eb'><div align='center'>{$g_chinayear[$i]}</td></div><td bgColor='#e7ebef'>"."<input size='5' name=\"r27_{$subid}_{$ii}\" value='{$val}'>"."<input type='button' value='-' onclick=m1(r27_{$subid}_{$ii},-0.01)>"."<input type='button' value='+' onclick=m1(r27_{$subid}_{$ii},0.01)></td>";
        ++$i;
    }
    $htm .= "</table></td><td valign=\"top\"></td></tr></table>";
    $htm .= "<br>";
    $rs->next();
}
$tpl->set( "htm_list", $htm );
$tpl->show( "main" );
?>